package com.spic.business.registrationform.controller;

import com.spic.business.registrationform.domain.ArchiveStaffDisciplinaryRecords;
import com.spic.business.registrationform.service.IArchiveStaffDisciplinaryRecordsService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 员工安全生产奖惩记录Controller
 * 
 * @author spic
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/disciplinary/records")
public class ArchiveStaffDisciplinaryRecordsController extends BaseController
{
    @Autowired
    private IArchiveStaffDisciplinaryRecordsService archiveStaffDisciplinaryRecordsService;

    /**
     * 查询员工安全生产奖惩记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArchiveStaffDisciplinaryRecords archiveStaffDisciplinaryRecords)
    {
        startPage();
        List<ArchiveStaffDisciplinaryRecords> list = archiveStaffDisciplinaryRecordsService.selectArchiveStaffDisciplinaryRecordsList(archiveStaffDisciplinaryRecords);
        return getDataTable(list);
    }

    /**
     * 导出员工安全生产奖惩记录列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveStaffDisciplinaryRecords archiveStaffDisciplinaryRecords) throws IOException {
        List<ArchiveStaffDisciplinaryRecords> list = archiveStaffDisciplinaryRecordsService.selectArchiveStaffDisciplinaryRecordsList(archiveStaffDisciplinaryRecords);
        ExcelUtil<ArchiveStaffDisciplinaryRecords> util = new ExcelUtil<ArchiveStaffDisciplinaryRecords>(ArchiveStaffDisciplinaryRecords.class);
        util.exportExcel(response, list, "员工安全生产奖惩记录数据");
    }

    /**
     * 获取员工安全生产奖惩记录详细信息
     */
    @GetMapping(value = "/{rewardsId}")
    public AjaxResult getInfo(@PathVariable("rewardsId") Long rewardsId)
    {
        return AjaxResult.success(archiveStaffDisciplinaryRecordsService.selectArchiveStaffDisciplinaryRecordsByRewardsId(rewardsId));
    }

    /**
     * 新增员工安全生产奖惩记录
     */
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveStaffDisciplinaryRecords archiveStaffDisciplinaryRecords)
    {
        return toAjax(archiveStaffDisciplinaryRecordsService.insertArchiveStaffDisciplinaryRecords(archiveStaffDisciplinaryRecords));
    }

    /**
     * 修改员工安全生产奖惩记录
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveStaffDisciplinaryRecords archiveStaffDisciplinaryRecords)
    {
        return toAjax(archiveStaffDisciplinaryRecordsService.updateArchiveStaffDisciplinaryRecords(archiveStaffDisciplinaryRecords));
    }

    /**
     * 删除员工安全生产奖惩记录
     */
	@DeleteMapping("/{rewardsIds}")
    public AjaxResult remove(@PathVariable Long[] rewardsIds)
    {
        return toAjax(archiveStaffDisciplinaryRecordsService.deleteArchiveStaffDisciplinaryRecordsByRewardsIds(rewardsIds));
    }
}
